<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box">
        <input type="text" name="" id="" v-model="a">
        {{aDouble}}
        <div>
            {{aPuls}}
        </div>
        <button @click="change()">修改</button>
    </div>
    <!-- computed:计算属性的结果会被缓存 如果之前有缓存值就不会每次都调用 -->
    <script src="./js/vue.js"> </script>
    <script>
        let vm = new Vue({
            el:'#box',
            data:{
               msg:10,
               a:10
            },
            computed:{
                // 仅读取
                aDouble(){
                    console.log(this.msg*2);
                    return this.msg*2
                },
                // 读取和设置
                aPuls:{
                    // 没有更改时触发get
                    get(){
                        return this.a
                    } ,
                    // 更改后触发set
                    set(v){
                       this.a = v-1
                    }
                }
            },
            methods:{
                change(){
                    this.aPuls=10
                }
            }
        })
    </script>
</body>
</html>